package cn.itcast.feign.client.fallback;
import cn.itcast.feign.client.UserClient;
import cn.itcast.feign.pojo.User;
import feign.hystrix.FallbackFactory;

/**
 * @author mrchen
 * @date 2022/6/25 16:05
 */
public class UserClientFallback implements FallbackFactory<UserClient> {
    /**
     * @param cause : 远程调用时，所产生的异常对象
     * @return
     */
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            /**
             * 服务降级方法
             * @param id
             * @return
             */
            @Override
            public User queryById(Long id) {
                User user = new User();
                user.setId(0L);
                user.setUsername("默认用户");
                user.setAddress("默认地址");
                return user;
            }

            @Override
            public String save(User user) {
                return null;
            }
        };
    }
}
